<?php 
namespace App\Services;

use Config;
use Response;
use View;
use URL;

/*
 * @author Bean
 * 错误码
 * */
class Msg{

	public static $msg_arr; /* 默认提示信息数组 */
	public $default; /* 默认提示信息 */

	const DEFAULT_MSG = "系统忙，请稍后再试";
	const MSG_BLADE = "admin.msg";

	/* 实例化 */
	public static function getMsg($sta){

		$msg = self::DEFAULT_MSG;
		
		$_msg_arr = Config::get('msg');

		if(isset($_msg_arr[$sta])){
			$msg = $_msg_arr[$sta];
		}

		return $msg;
	}


	public static function send($sta,$data="",$redirect=""){


		$res = compact("sta","data","redirect");

		return json_encode($res);
	}

    public static function showMsg($rsCode,$msg = "",$url=""){
       
       	if($rsCode != 0){
       		$msg       = self::getMsg($rsCode);
       	}

        $targetUrl = URL::previous();

        if(trim($url) != ""){
            $targetUrl = $url;
        }

        $title     = "Redirecting to {{$targetUrl}}";
        
        $res = compact("msg","failed","title","targetUrl","rsCode");

		return view(self::MSG_BLADE,$res);
    }	

}

?>